package com.example.pclimb.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.example.pclimb.model.UserLike;

/**
 * 用户点赞记录数据访问接口
 */
@Dao
public interface UserLikeDao {
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(UserLike userLike);
    
    @Delete
    void delete(UserLike userLike);
    
    @Query("SELECT COUNT(*) FROM user_likes WHERE userId = :userId AND guideId = :guideId")
    LiveData<Integer> isLiked(int userId, int guideId);
    
    @Query("SELECT * FROM user_likes WHERE userId = :userId AND guideId = :guideId")
    LiveData<UserLike> getUserLike(int userId, int guideId);
    
    @Query("DELETE FROM user_likes WHERE userId = :userId AND guideId = :guideId")
    void deleteUserLike(int userId, int guideId);
    
    @Query("SELECT COUNT(*) FROM user_likes WHERE guideId = :guideId")
    LiveData<Integer> getLikeCount(int guideId);
    
    @Query("SELECT COUNT(*) FROM user_likes WHERE userId = :userId")
    LiveData<Integer> getUserLikeCount(int userId);
} 